import {createRouter,createWebHashHistory} from 'vue-router'
import store from '../store';
import Index from '../view/Index/index.vue'
import Login from '../view/Login/index.vue'
import Layout from '../layout/default.vue'
import Home from '../view/Home/index.vue'
// 产品路由
import Product from '../view/Product/index.vue'
import AddProduct from '../view/Product/add.vue'
import EditProduct from '../view/Product/edit.vue'
import AreaProduct from '../view/Product/area.vue'

import News from '../view/News/index.vue'
import AddNews from '../view/News/add.vue'
import EditNews from '../view/News/edit.vue'

import Article from '../view/Article/index.vue'
import AddArticle from '../view/Article/add.vue'
import EditArticle from '../view/Article/edit.vue'

import Order from '../view/Order/index.vue'
import OrderDetail from '../view/Order/detail.vue'
import Menu  from '../view/Menu/index.vue'
import ConfigLists from '../view/Configure/lists.vue'
import Setting from '../view/Configure/group.vue'
import System from '../view/System/index.vue'
import Category from '../view/Category/index.vue'
import AddCategory from '../view/Category/add.vue'
import EditCategory from '../view/Category/edit.vue'
import Role from '../view/Role/index.vue'
import Access from '../view/Access/index.vue'
import Manager from '../view/System/manager.vue'
import Banner from '../view/Banner/index.vue'
import User from '../view/User/index.vue'

const routes = [
	{path:'/login',component:Login,name:'login'},
	{
		path:'/',
		name:'首页',
		component:Layout,
		children:[
			{
			  	path: '',
				name:'首页',
			  	component:Home
			},
			{
			  	path: '/index',
			  	component:Home
			},
			{
				path:'/menu',
				name:'菜单管理',
				component:Menu
			},
			{path:'/banner/index',name:'轮播图列表',component:Banner},
			{path:'/order/index',name:'订单列表',component:Order},
			{path:'/order/edit',name:'订单编辑',component:Order},
			{path:'/order/detail',name:'订单详情',component:OrderDetail},
			{path:'/product/index',name:'产品列表',component:Product},
			{path:'/product/add',name:'添加产品',component:AddProduct},
			{path:'/product/edit',name:'编辑产品',component:EditProduct},
			{path:'/product/area',name:'产品分区',component:AreaProduct},
			{path:'/system',name:'系统管理',component:System},
			{path:'/setting',name:'系统配置分组',component:Setting},
			{path:'/config/lists',name:'系统配置',component:ConfigLists},
			{path:'/category/index',name:'分类列表',component:Category},
			{path:'/category/add',name:'添加分类',component:AddCategory},
			{path:'/role/index',name:'角色',component:Role},
			{path:'/access/index',name:'权限',component:Access},
			{path:'/system/admin',name:'管理员',component:Manager},
			{path:'/user/index',name:'用户管理',component:User},
			{path:'/article/lists',name:'文章列表',component:Article},
			{path:'/article/edit',name:'bianji',component:EditArticle},
			{path:'/article/add',name:'add',component:AddArticle},
			{path:'/news/lists',name:'新闻列表',component:News},
			{path:'/news/add',name:'添加新闻',component:AddNews},
			{path:'/news/edit',name:'编辑新闻',component:EditNews},
		]
	},
];


const router = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHashHistory(),
  routes, // `routes: routes` 的缩写
})

 router.beforeEach((to,from)=>{
 	store.commit('setHeader',{header:to.name});
		store.commit('pushNav',{nav:{path:to.path,name:to.name}});
	 if( to.path != '/login') {
	 	var token = localStorage.getItem('token');
		if(!token) {
			router.push('/login');
		}
	}
})
export default router;